package com.jiuyi.controller;

import com.jiuyi.common.R;
import com.jiuyi.service.CommonService;
import com.jiuyi.service.Impl.CommonServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.UUID;

/**
 * DATA: 2022/10/20
 * Author: 晨夕
 */
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonServiceImpl commonServiceImpl;

    /**
     * 文件上传
     */
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        return commonServiceImpl.uploadFile(file);
    }

    /**
     * 文件下载
     */
    @GetMapping("/download")
    public void download(String name, HttpServletResponse response){
        commonServiceImpl.downloadFile(name,response);
    }
}
